﻿// Copyright (C) 2009 Choonghwan Lee (linjus.lee@gmail.com)
//
// This file is part of amanda.
//
// amanda is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// amanda is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with amanda. If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.IO;

namespace manager
{
	public partial class LibraryInfo
	{
		public bool Validate()
		{
			if (!this.PlaylistRootPath.EndsWith("\\"))
				this.PlaylistRootPath = this.PlaylistRootPath + "\\";
			if (!this.DeviceRootPath.EndsWith("\\"))
				this.DeviceRootPath = this.DeviceRootPath + "\\";

			foreach (DeviceInfo dev in Configuration.Devices) {
				if (dev.Name == this.DeviceName) {
					this.device = dev;
					return true;
				}
			}
			return false;
		}

		private DeviceInfo device;
		public DeviceInfo Device
		{ get { return this.device; } }
	}

	public partial class DeviceInfo
	{
		public bool RequireTranscoding(Encoding type)
		{
			foreach (Encoding allowed in this.Encoder) {
				if (allowed == type)
					return false;
			}
			return true;
		}

		public Encoding TranscodedType(Encoding type)
		{
			if (!this.RequireTranscoding(type))
				return type;

			return Encoding.MP3;
		}

		public List<RuleAction> DetermineActions(Track track)
		{
			List<RuleAction> actions = new List<RuleAction>();

			if (this.RequireTranscoding(track.Encoding)) {
				TranscodingAction action = new TranscodingAction(track.Encoding);
				actions.Add(action);
			}
			if (this.Text == TextRule.LATIN) {
				RomanizationAction action = new RomanizationAction();
				actions.Add(action);
			}
			if (this.Artwork == ArtworkRule.EMBED) {
				ArtworkEmbedAction action = new ArtworkEmbedAction();
				actions.Add(action);
			}
			if (this.Structure == StructureRule.ONELEVEL) {
				FlattenStructureAction action = new FlattenStructureAction();
				actions.Add(action);
			}

			return actions;
		}
	}
}
